package com.mvc4g.example.shareModel.client.view.views;

import java.util.HashMap;
import java.util.Map;

import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.mvc4g.example.shareModel.client.bean.BeanA;
import com.mvc4g.example.shareModel.client.bean.BeanB;
import com.mvc4g.example.shareModel.client.bean.BeanC;

public class ViewB extends AbstractView {

	private Label labelA = null;
	private Label labelB = null;
	private Label labelC = null;

	private BeanB modelB = null;
	private Map<String, Object> externalModels = new HashMap<String, Object>();

	@Override
	protected Widget createWidget() {

		labelA = new Label();
		labelB = new Label();
		labelC = new Label();

		VerticalPanel mainPanel = new VerticalPanel();
		mainPanel.add(labelB);
		mainPanel.add(labelA);
		mainPanel.add(labelC);

		return mainPanel;
	}

	public void init() {
		labelA.setText("Information received from A: "
				+ ((BeanA) externalModels.get(MODEL_A)).getInfo());
		labelB.setText("Information of B: " + modelB.getInfo());
		labelC.setText("Information received from C: "
				+ ((BeanC) externalModels.get(MODEL_C)).getInfo());
	}
	
	public void restart(){
		modelB = null;
		externalModels.clear();
	}
	
	public void setModelB(BeanB modelB) {
		this.modelB = modelB;		
	}

	public void setModel(String key, Object value) {
		externalModels.put(key, value);
	}

	public Object getModel(String key) {
		return externalModels.get(key);
	}

}
